<?php
use App\Models\Reply;

return [
    'title'=>'评论',
    'single'=>'评论',
    'model'=>Reply::class,
    'columns'=>[
        'id'=>[
            'title'=>'ID'
        ],
        'content'=>[
            'title'=>'内容',
            'sortable'=>false,
            'output'=>function($value,$model){
                return "<div style='max-width: 220px;'>$value</div>";
            }
        ],
        'user'=>[
            'title'=>'作者',
            'sortable'=>false,
            'output'=>function($value,$model){
                $avatar = $model->user->avatar;
                $value = empty($avatar) ? 'N/A' : "<img src='$avatar'
                style='width:22px;height:22px;'/>{$model->user->name}";
                return model_link($value,$model->user);
            }
        ],
        'topic'=>[
            'title'=>'帖子',
            'sortable'=>false,
            'output'=>function($value,$model){
                return "<div style='max-width:260px'>".model_admin_link(e($model->topic->title),$model->topic)."</div>";
            },
            'operation'=>[
                'title'=>'管理',
                'sortable'=>false
            ]
        ]
    ],
    'edit_fields'=>[
        'user'=>[
            'title'=>'用户',
            'type'=>'relationship',
            'name_field'=>'name',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],
        'topic'=>[
            'title'=>'帖子',
            'type'=>'relationship',
            'name_field'=>'title',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',title)"],
            'options_sort_field'=>'id'
        ],
        'content'=>[
            'title'=>'评论内容',
            'type'=>'textarea'
        ]
    ],
    'filters'=>[
        'user'=>[
            'title'=>'用户',
            'type'=>'relationship',
            'name_field' => 'name',
            'autocomplete' => true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],
        'topic'=>[
            'title'=>'帖子',
            'type'=>'relationship',
            'name_field' => 'title',
            'autocomplete' => true,
            'search_fields'=>["CONCAT(id,' ',title)"],
            'options_sort_field'=>'id'
        ],
        'content'=>[
            'title'=>'回复内容',
        ]
    ],
    'rules'=>[
        'content'=>'required'
    ],
    'messages'=>[
        'content.required'=>'请填写评论内容'
    ]
];
